package main;

import dao.PhoneBookDao;
import entity.Phone;


import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * @Description
 * @Author:PrinceHan
 * @CreateTime:2021/11/30 19:55
 */
public class PhoneBook_JDBC {
    static PhoneBookDao dao = new PhoneBookDao();
    public static void main(String[] args) throws SQLException {
        Scanner scanner = new Scanner(System.in);
        String name;
        String tel;
        int op = 0;
        /*
        int index = -1;
        boolean isInPhoneBook = false;
        */

        ArrayList<Phone> Phones = new ArrayList<>();
        //控制界面
        System.out.println("*******************电话本******************");
        System.out.println();
        System.out.println("1.添加*************2.删除*************3.修改");
        System.out.println();
        System.out.println("4.查询*************5.打印*************6.退出");
        System.out.println();
        System.out.println("*******************电话本******************");
        while (true) {
            System.out.println("请输入你要执行的操作:");
            op = scanner.nextInt();
            switch (op) {
                case 1:
                    System.out.println("请输入你要添加的联系人的姓名:");
                    name = scanner.next();
                    System.out.println("请输入你要添加的联系人的号码:");
                    tel = scanner.next();
                    boolean result = dao.addPhone(name, tel);
                    if(result) {
                        System.out.println("添加成功");
                        Phone phone = new Phone(name, tel);
                        System.out.println(phone.toString());
                    } else {
                        System.out.println("添加失败");
                    }
                    break;
                case 2:

                    break;
                case 3:

                    break;
                case 4:

                    break;
                case 5:
                    Phones = dao.PrintAll();
                    for(Phone phone: Phones) {
                        System.out.println(phone.toString());
                    }
                    break;
                case 6:
                    scanner.close();
                    System.out.println("退出电话本！！！");
                    System.exit(0);
                    break;
                default:
                    System.out.println("请输入1~6");
                    break;
            }
        }
    }
}
